<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of v_bark2frq</title>
  <meta name="keywords" content="v_bark2frq">
  <meta name="description" content="V_BARK2FRQ  Convert the BARK frequency scale to Hertz FRQ=(BARK)">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">v_mfiles</a> &gt; v_bark2frq.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for v_mfiles&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>v_bark2frq
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>V_BARK2FRQ  Convert the BARK frequency scale to Hertz FRQ=(BARK)</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [f,c] = v_bark2frq(b,m) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">V_BARK2FRQ  Convert the BARK frequency scale to Hertz FRQ=(BARK)

 Inputs: b  matrix of frequencies in Bark
         m  mode options
            'h'   use high frequency correction from [1]
            'l'   use low frequency correction from [1]
            'H'   do not apply any high frequency correction
            'L'   do not apply any low frequency correction
            'u'   unipolar version: do not force b to be an odd function
                  This has no effect on the default function which is odd anyway
            's'   use the expression from Schroeder et al. (1979)
            'g'   plot a graph

 Outputs: f  frequency values in Hz
          c  Critical bandwidth: d(freq)/d(bark)</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="v_frq2bark.html" class="code" title="function [b,c] = v_frq2bark(f,m)">v_frq2bark</a>	V_FRQ2BARK  Convert Hertz to BARK frequency scale BARK=(FRQ)</li><li><a href="v_yticksi.html" class="code" title="function s=v_yticksi(ah)">v_yticksi</a>	V_YTIXKSI labels the y-axis of a plot using SI multipliers S=(AH)</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="v_filtbankm.html" class="code" title="function [x,cf,il,ih]=v_filtbankm(p,n,fs,fl,fh,w)">v_filtbankm</a>	V_FILTBANKM determine matrix for a linear/mel/erb/bark-spaced v_filterbank [X,IL,IH]=(P,N,FS,FL,FH,W)</li><li><a href="v_gammabank.html" class="code" title="function [b,a,fx,bx,gd,ph]=v_gammabank(n,fs,w,fc,bw,ph,k)">v_gammabank</a>	V_GAMMABANK gammatone filter bank [b,a,fx,bx,gd]=(n,fs,w,fc,bw,ph,k)</li><li><a href="v_melbankm.html" class="code" title="function [x,mc,mn,mx]=v_melbankm(p,n,fs,fl,fh,w)">v_melbankm</a>	V_MELBANKM determine matrix for a mel/erb/bark-spaced v_filterbank [X,MN,MX]=(P,N,FS,FL,FH,W)</li><li><a href="v_spgrambw.html" class="code" title="function [t,f,b]=v_spgrambw(s,fs,varargin)">v_spgrambw</a>	V_SPGRAMBW Draw spectrogram [T,F,B]=(s,fs,mode,bw,fmax,db,tinc,ann)</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [f,c] = v_bark2frq(b,m)</a>
0002 <span class="comment">%V_BARK2FRQ  Convert the BARK frequency scale to Hertz FRQ=(BARK)</span>
0003 <span class="comment">%</span>
0004 <span class="comment">% Inputs: b  matrix of frequencies in Bark</span>
0005 <span class="comment">%         m  mode options</span>
0006 <span class="comment">%            'h'   use high frequency correction from [1]</span>
0007 <span class="comment">%            'l'   use low frequency correction from [1]</span>
0008 <span class="comment">%            'H'   do not apply any high frequency correction</span>
0009 <span class="comment">%            'L'   do not apply any low frequency correction</span>
0010 <span class="comment">%            'u'   unipolar version: do not force b to be an odd function</span>
0011 <span class="comment">%                  This has no effect on the default function which is odd anyway</span>
0012 <span class="comment">%            's'   use the expression from Schroeder et al. (1979)</span>
0013 <span class="comment">%            'g'   plot a graph</span>
0014 <span class="comment">%</span>
0015 <span class="comment">% Outputs: f  frequency values in Hz</span>
0016 <span class="comment">%          c  Critical bandwidth: d(freq)/d(bark)</span>
0017 
0018 <span class="comment">%   The Bark scale was defined by an ISO committee and published in [2]. It</span>
0019 <span class="comment">%   was based on a varienty of experiments on the thresholds for complex</span>
0020 <span class="comment">%   sounds, masking, perception of phase and the loudness of complex</span>
0021 <span class="comment">%   sounds. The Bark scale is named in honour of Barkhausen, the creator</span>
0022 <span class="comment">%   of the unit of loudness level [2]. Critical band k extends</span>
0023 <span class="comment">%   from v_bark2frq(k-1) to v_bark2frq(k). The inverse function is v_frq2bark.</span>
0024 <span class="comment">%</span>
0025 <span class="comment">%   There are many published formulae approximating the Bark scale.</span>
0026 <span class="comment">%   The default is the one from [1] but with a correction at high and</span>
0027 <span class="comment">%   low frequencies to give a better fit to [2] with a continuous derivative</span>
0028 <span class="comment">%   and ensure that 0 Hz = 0 Bark.</span>
0029 <span class="comment">%   The h and l mode options apply the corrections from [1] which are</span>
0030 <span class="comment">%   not as good and do not give a continuous derivative. The H and L</span>
0031 <span class="comment">%   mode options suppress the correction entirely to give a simple formula.</span>
0032 <span class="comment">%   The 's' option uses the less accurate formulae from [3] which have been</span>
0033 <span class="comment">%   widely used in the lterature.</span>
0034 <span class="comment">%</span>
0035 <span class="comment">%   [1] H. Traunmuller, Analytical Expressions for the</span>
0036 <span class="comment">%       Tonotopic Sensory Scale�, J. Acoust. Soc. Am. 88,</span>
0037 <span class="comment">%       1990, pp. 97-100.</span>
0038 <span class="comment">%   [2] E. Zwicker, Subdivision of the audible frequency range into</span>
0039 <span class="comment">%       critical bands, J Accoust Soc Am 33, 1961, p248.</span>
0040 <span class="comment">%   [3] M. R. Schroeder, B. S. Atal, and J. L. Hall. Optimizing digital</span>
0041 <span class="comment">%       speech coders by exploiting masking properties of the human ear.</span>
0042 <span class="comment">%       J. Acoust Soc Amer, 66 (6): 1647�1652, 1979. doi: 10.1121/1.383662.</span>
0043 
0044 <span class="comment">%      Copyright (C) Mike Brookes 2006-2010</span>
0045 <span class="comment">%      Version: $Id: v_bark2frq.m 10865 2018-09-21 17:22:45Z dmb $</span>
0046 <span class="comment">%</span>
0047 <span class="comment">%   VOICEBOX is a MATLAB toolbox for speech processing.</span>
0048 <span class="comment">%   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html</span>
0049 <span class="comment">%</span>
0050 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0051 <span class="comment">%   This program is free software; you can redistribute it and/or modify</span>
0052 <span class="comment">%   it under the terms of the GNU General Public License as published by</span>
0053 <span class="comment">%   the Free Software Foundation; either version 2 of the License, or</span>
0054 <span class="comment">%   (at your option) any later version.</span>
0055 <span class="comment">%</span>
0056 <span class="comment">%   This program is distributed in the hope that it will be useful,</span>
0057 <span class="comment">%   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
0058 <span class="comment">%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
0059 <span class="comment">%   GNU General Public License for more details.</span>
0060 <span class="comment">%</span>
0061 <span class="comment">%   You can obtain a copy of the GNU General Public License from</span>
0062 <span class="comment">%   http://www.gnu.org/copyleft/gpl.html or by writing to</span>
0063 <span class="comment">%   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.</span>
0064 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0065 <span class="keyword">persistent</span> A B C E D P Q R S T U V W X Y Z
0066 <span class="keyword">if</span> isempty(P)
0067     A=26.81;
0068     B=1960;
0069     C=-0.53;
0070     E = A+C;
0071     D=A*B;
0072     P=(0.53/(3.53)^2);
0073     V=3-0.5/P;
0074     W=V^2-9;
0075     Q=0.25;
0076     R=20.4;
0077     xy=2;
0078     S=0.5*Q/xy;
0079     T=R+0.5*xy;
0080     U=T-xy;
0081     X = T*(1+Q)-Q*R;
0082     Y = U-0.5/S;
0083     Z=Y^2-U^2;
0084 <span class="keyword">end</span>
0085 <span class="keyword">if</span> nargin&lt;2
0086     m=<span class="string">' '</span>;
0087 <span class="keyword">end</span>
0088 <span class="keyword">if</span> any(m==<span class="string">'u'</span>)
0089     a=b;
0090 <span class="keyword">else</span>
0091     a=abs(b);
0092 <span class="keyword">end</span>
0093 <span class="keyword">if</span> any(m==<span class="string">'s'</span>)
0094     f=650*sinh(a/7);
0095 <span class="keyword">else</span>
0096     <span class="keyword">if</span> any(m==<span class="string">'l'</span>)
0097         m1=(a&lt;2);
0098         a(m1)=(a(m1)-0.3)/0.85;
0099     <span class="keyword">elseif</span> ~any(m==<span class="string">'L'</span>)
0100         m1=(a&lt;3);
0101         a(m1)=V+sqrt(W+a(m1)/P);
0102     <span class="keyword">end</span>
0103     <span class="keyword">if</span> any(m==<span class="string">'h'</span>)
0104         m1=(a&gt;20.1);
0105         a(m1)=(a(m1)+4.422)/1.22;
0106     <span class="keyword">elseif</span> ~any(m==<span class="string">'H'</span>)
0107         m2=(a&gt;X);
0108         m1=(a&gt;U) &amp; ~m2;
0109         a(m2)=(a(m2)+Q*R)/(1+Q);
0110         a(m1)=Y+sqrt(Z+a(m1)/S);
0111     <span class="keyword">end</span>
0112     f=(D*(E-a).^(-1)-B);
0113 <span class="keyword">end</span>
0114 <span class="keyword">if</span> ~any(m==<span class="string">'u'</span>)
0115     f=f.*sign(b);          <span class="comment">% force to be odd</span>
0116 <span class="keyword">end</span>
0117 <span class="keyword">if</span> nargout&gt;1
0118     [bx,c] = <a href="v_frq2bark.html" class="code" title="function [b,c] = v_frq2bark(f,m)">v_frq2bark</a>(f,m);
0119 <span class="keyword">end</span>
0120 <span class="keyword">if</span> ~nargout || any(m==<span class="string">'g'</span>)
0121     [bx,c] = <a href="v_frq2bark.html" class="code" title="function [b,c] = v_frq2bark(f,m)">v_frq2bark</a>(f,m);
0122     subplot(212)
0123     semilogy(b,c,<span class="string">'-r'</span>);
0124     ha=gca;
0125     xlabel(<span class="string">'Bark'</span>);
0126     ylabel([<span class="string">'Critical BW ('</span> <a href="v_yticksi.html" class="code" title="function s=v_yticksi(ah)">v_yticksi</a> <span class="string">'Hz)'</span>]);
0127     subplot(211)
0128     plot(b,f,<span class="string">'x-b'</span>);
0129     hb=gca;
0130     xlabel(<span class="string">'Bark'</span>);
0131     ylabel([<span class="string">'Frequency ('</span> <a href="v_yticksi.html" class="code" title="function s=v_yticksi(ah)">v_yticksi</a> <span class="string">'Hz)'</span>]);
0132     linkaxes([ha hb],<span class="string">'x'</span>);
0133 <span class="keyword">end</span></pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>